package com.net.lnk.batch.bank.web;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/import")
public class ImportController {

	@Autowired
	private JobLauncher jobLauncher;

	@Autowired
	private Job importBankcardJob;

	@GetMapping("/bankcard")
	public String importBankcard(String fileName) throws Exception {
		String fullFileName = fileName + ".csv";
		JobParameters jobParameters = new JobParametersBuilder().addString("input.file.name", fullFileName)
				.toJobParameters();
		jobLauncher.run(importBankcardJob, jobParameters);

		return "OK";
	}

}
